using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace ICP_MS.Plugin.Tune;

[ToolboxBitmap(typeof(TrackBar))]
[DefaultEvent("Scroll")]
[DefaultProperty("BarInnerColor")]
public class ColorSlider : Control
{
	public enum ColorSchemas
	{
		PerlBlueGreen,
		PerlRedCoral,
		PerlGold,
		PerlRoyalColors
	}

	private Rectangle thumbRect;

	private Rectangle barRect;

	private Rectangle barHalfRect;

	private Rectangle thumbHalfRect;

	private Rectangle elapsedRect;

	private Rectangle tipRect;

	private Rectangle tipHalfRect;

	private int thumbSize = 15;

	private GraphicsPath thumbCustomShape = null;

	private Size thumbRoundRectSize = new Size(8, 8);

	private Size borderRoundRectSize = new Size(8, 8);

	private Orientation barOrientation = Orientation.Horizontal;

	private int trackerValue = 50;

	private int _tipMin = -1;

	private int _tipMax = -1;

	private int barMinimum = 0;

	private int barMaximum = 100;

	private uint smallChange = 1u;

	private uint largeChange = 5u;

	private bool drawFocusRectangle = true;

	private bool drawSemitransparentThumb = true;

	private bool mouseEffects = true;

	private int mouseWheelBarPartitions = 10;

	private Color thumbOuterColor = Color.White;

	private Color thumbInnerColor = Color.Gainsboro;

	private Color thumbPenColor = Color.Silver;

	private Color barOuterColor = Color.SkyBlue;

	private Color barInnerColor = Color.DarkSlateBlue;

	private Color barPenColor = Color.Gainsboro;

	private Color elapsedOuterColor = Color.DarkGreen;

	private Color elapsedInnerColor = Color.Chartreuse;

	private Color tipColor = Color.Yellow;

	private Color[,] aColorSchema = new Color[4, 9]
	{
		{
			Color.White,
			Color.Gainsboro,
			Color.Black,
			Color.SkyBlue,
			Color.SkyBlue,
			Color.Gainsboro,
			Color.Blue,
			Color.Blue,
			Color.Yellow
		},
		{
			Color.White,
			Color.Gainsboro,
			Color.Black,
			Color.Red,
			Color.DarkRed,
			Color.Gainsboro,
			Color.Coral,
			Color.LightCoral,
			Color.Yellow
		},
		{
			Color.White,
			Color.Gainsboro,
			Color.Black,
			Color.GreenYellow,
			Color.Yellow,
			Color.Gold,
			Color.Orange,
			Color.OrangeRed,
			Color.Yellow
		},
		{
			Color.White,
			Color.Gainsboro,
			Color.Black,
			Color.Red,
			Color.Crimson,
			Color.Gainsboro,
			Color.DarkViolet,
			Color.Violet,
			Color.Yellow
		}
	};

	private ColorSchemas colorSchema = ColorSchemas.PerlBlueGreen;

	private bool mouseInRegion = false;

	private bool mouseInThumbRegion = false;

	private IContainer components = null;

	[Browsable(false)]
	public Rectangle ThumbRect => thumbRect;

	[Description("Set Slider thumb size")]
	[Category("ColorSlider")]
	[DefaultValue(15)]
	public int ThumbSize
	{
		get
		{
			return thumbSize;
		}
		set
		{
			if ((value > 0) & (value < ((barOrientation == Orientation.Horizontal) ? base.ClientRectangle.Width : base.ClientRectangle.Height)))
			{
				thumbSize = value;
				Invalidate();
				return;
			}
			throw new ArgumentOutOfRangeException("TrackSize has to be greather than zero and lower than half of Slider width");
		}
	}

	[Description("Set Slider's thumb's custom shape")]
	[Category("ColorSlider")]
	[Browsable(false)]
	[DefaultValue(typeof(GraphicsPath), "null")]
	public GraphicsPath ThumbCustomShape
	{
		get
		{
			return thumbCustomShape;
		}
		set
		{
			thumbCustomShape = value;
			thumbSize = (int)((barOrientation == Orientation.Horizontal) ? value.GetBounds().Width : value.GetBounds().Height) + 1;
			Invalidate();
		}
	}

	[Description("Set Slider's thumb round rect size")]
	[Category("ColorSlider")]
	[DefaultValue(typeof(Size), "8; 8")]
	public Size ThumbRoundRectSize
	{
		get
		{
			return thumbRoundRectSize;
		}
		set
		{
			int h = value.Height;
			int w = value.Width;
			if (h <= 0)
			{
				h = 1;
			}
			if (w <= 0)
			{
				w = 1;
			}
			thumbRoundRectSize = new Size(w, h);
			Invalidate();
		}
	}

	[Description("Set Slider's border round rect size")]
	[Category("ColorSlider")]
	[DefaultValue(typeof(Size), "8; 8")]
	public Size BorderRoundRectSize
	{
		get
		{
			return borderRoundRectSize;
		}
		set
		{
			int h = value.Height;
			int w = value.Width;
			if (h <= 0)
			{
				h = 1;
			}
			if (w <= 0)
			{
				w = 1;
			}
			borderRoundRectSize = new Size(w, h);
			Invalidate();
		}
	}

	[Description("Set Slider orientation")]
	[Category("ColorSlider")]
	[DefaultValue(Orientation.Horizontal)]
	public Orientation Orientation
	{
		get
		{
			return barOrientation;
		}
		set
		{
			if (barOrientation != value)
			{
				barOrientation = value;
				int temp = base.Width;
				base.Width = base.Height;
				base.Height = temp;
				if (thumbCustomShape != null)
				{
					thumbSize = (int)((barOrientation == Orientation.Horizontal) ? thumbCustomShape.GetBounds().Width : thumbCustomShape.GetBounds().Height) + 1;
				}
				Invalidate();
			}
		}
	}

	[Description("Set Slider value")]
	[Category("ColorSlider")]
	[DefaultValue(50)]
	public int Value
	{
		get
		{
			return trackerValue;
		}
		set
		{
			if ((value >= barMinimum) & (value <= barMaximum))
			{
				trackerValue = value;
				if (this.ValueChanged != null)
				{
					this.ValueChanged(this, new EventArgs());
				}
				Invalidate();
			}
		}
	}

	[Description("Set Slider value")]
	[Category("ColorSlider")]
	[DefaultValue(-1)]
	public int TipMin
	{
		get
		{
			return _tipMin;
		}
		set
		{
			_tipMin = value;
		}
	}

	[Description("Set Slider value")]
	[Category("ColorSlider")]
	[DefaultValue(-1)]
	public int TipMax
	{
		get
		{
			return _tipMax;
		}
		set
		{
			_tipMax = value;
		}
	}

	[Description("Set Slider minimal point")]
	[Category("ColorSlider")]
	[DefaultValue(0)]
	public int Minimum
	{
		get
		{
			return barMinimum;
		}
		set
		{
			if (value >= barMaximum)
			{
				return;
			}
			barMinimum = value;
			if (trackerValue < barMinimum)
			{
				trackerValue = barMinimum;
				if (this.ValueChanged != null)
				{
					this.ValueChanged(this, new EventArgs());
				}
			}
			Invalidate();
		}
	}

	[Description("Set Slider maximal point")]
	[Category("ColorSlider")]
	[DefaultValue(100)]
	public int Maximum
	{
		get
		{
			return barMaximum;
		}
		set
		{
			if (value <= barMinimum)
			{
				return;
			}
			barMaximum = value;
			if (trackerValue > barMaximum)
			{
				trackerValue = barMaximum;
				if (this.ValueChanged != null)
				{
					this.ValueChanged(this, new EventArgs());
				}
			}
			Invalidate();
		}
	}

	[Description("Set trackbar's small change")]
	[Category("ColorSlider")]
	[DefaultValue(1)]
	public uint SmallChange
	{
		get
		{
			return smallChange;
		}
		set
		{
			smallChange = value;
		}
	}

	[Description("Set trackbar's large change")]
	[Category("ColorSlider")]
	[DefaultValue(5)]
	public uint LargeChange
	{
		get
		{
			return largeChange;
		}
		set
		{
			largeChange = value;
		}
	}

	[Description("Set whether to draw focus rectangle")]
	[Category("ColorSlider")]
	[DefaultValue(true)]
	public bool DrawFocusRectangle
	{
		get
		{
			return drawFocusRectangle;
		}
		set
		{
			drawFocusRectangle = value;
			Invalidate();
		}
	}

	[Description("Set whether to draw semitransparent thumb")]
	[Category("ColorSlider")]
	[DefaultValue(true)]
	public bool DrawSemitransparentThumb
	{
		get
		{
			return drawSemitransparentThumb;
		}
		set
		{
			drawSemitransparentThumb = value;
			Invalidate();
		}
	}

	[Description("Set whether mouse entry and exit actions have impact on how control look")]
	[Category("ColorSlider")]
	[DefaultValue(true)]
	public bool MouseEffects
	{
		get
		{
			return mouseEffects;
		}
		set
		{
			mouseEffects = value;
			Invalidate();
		}
	}

	[Description("Set to how many parts is bar divided when using mouse wheel")]
	[Category("ColorSlider")]
	[DefaultValue(10)]
	public int MouseWheelBarPartitions
	{
		get
		{
			return mouseWheelBarPartitions;
		}
		set
		{
			if (value > 0)
			{
				mouseWheelBarPartitions = value;
				return;
			}
			throw new ArgumentOutOfRangeException("MouseWheelBarPartitions has to be greather than zero");
		}
	}

	[Description("Set Slider thumb outer color")]
	[Category("ColorSlider")]
	[DefaultValue(typeof(Color), "White")]
	public Color ThumbOuterColor
	{
		get
		{
			return thumbOuterColor;
		}
		set
		{
			thumbOuterColor = value;
			Invalidate();
		}
	}

	[Description("Set Slider thumb inner color")]
	[Category("ColorSlider")]
	[DefaultValue(typeof(Color), "Gainsboro")]
	public Color ThumbInnerColor
	{
		get
		{
			return thumbInnerColor;
		}
		set
		{
			thumbInnerColor = value;
			Invalidate();
		}
	}

	[Description("Set Slider thumb pen color")]
	[Category("ColorSlider")]
	[DefaultValue(typeof(Color), "Silver")]
	public Color ThumbPenColor
	{
		get
		{
			return thumbPenColor;
		}
		set
		{
			thumbPenColor = value;
			Invalidate();
		}
	}

	[Description("Set Slider bar outer color")]
	[Category("ColorSlider")]
	[DefaultValue(typeof(Color), "SkyBlue")]
	public Color BarOuterColor
	{
		get
		{
			return barOuterColor;
		}
		set
		{
			barOuterColor = value;
			Invalidate();
		}
	}

	[Description("Set Slider bar inner color")]
	[Category("ColorSlider")]
	[DefaultValue(typeof(Color), "DarkSlateBlue")]
	public Color BarInnerColor
	{
		get
		{
			return barInnerColor;
		}
		set
		{
			barInnerColor = value;
			Invalidate();
		}
	}

	[Description("Set Slider bar pen color")]
	[Category("ColorSlider")]
	[DefaultValue(typeof(Color), "Gainsboro")]
	public Color BarPenColor
	{
		get
		{
			return barPenColor;
		}
		set
		{
			barPenColor = value;
			Invalidate();
		}
	}

	[Description("Set Slider's elapsed part outer color")]
	[Category("ColorSlider")]
	[DefaultValue(typeof(Color), "DarkGreen")]
	public Color ElapsedOuterColor
	{
		get
		{
			return elapsedOuterColor;
		}
		set
		{
			elapsedOuterColor = value;
			Invalidate();
		}
	}

	[Description("Set Slider's elapsed part inner color")]
	[Category("ColorSlider")]
	[DefaultValue(typeof(Color), "Chartreuse")]
	public Color ElapsedInnerColor
	{
		get
		{
			return elapsedInnerColor;
		}
		set
		{
			elapsedInnerColor = value;
			Invalidate();
		}
	}

	[Description("Set TipColor")]
	[Category("ColorSlider")]
	[DefaultValue(typeof(Color), "Yellow")]
	public Color TipColor
	{
		get
		{
			return tipColor;
		}
		set
		{
			tipColor = value;
			Invalidate();
		}
	}

	[Description("Set Slider color schema. Has no effect when slider colors are changed manually after schema was applied.")]
	[Category("ColorSlider")]
	[DefaultValue(typeof(ColorSchemas), "PerlBlueGreen")]
	public ColorSchemas ColorSchema
	{
		get
		{
			return colorSchema;
		}
		set
		{
			colorSchema = value;
			byte sn = (byte)value;
			thumbOuterColor = aColorSchema[sn, 0];
			thumbInnerColor = aColorSchema[sn, 1];
			thumbPenColor = aColorSchema[sn, 2];
			barOuterColor = aColorSchema[sn, 3];
			barInnerColor = aColorSchema[sn, 4];
			barPenColor = aColorSchema[sn, 5];
			elapsedOuterColor = aColorSchema[sn, 6];
			elapsedInnerColor = aColorSchema[sn, 7];
			tipColor = aColorSchema[sn, 8];
			Invalidate();
		}
	}

	[Description("Event fires when the Value property changes")]
	[Category("Action")]
	public event EventHandler ValueChanged;

	[Description("Event fires when the Slider position is changed")]
	[Category("Behavior")]
	public event ScrollEventHandler Scroll;

	public ColorSlider(int min, int max, int value)
	{
		InitializeComponent();
		SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.Selectable | ControlStyles.UserMouse | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
		BackColor = Color.Transparent;
		Minimum = min;
		Maximum = max;
		Value = value;
	}

	public ColorSlider()
		: this(0, 100, 50)
	{
	}

	protected override void OnPaint(PaintEventArgs e)
	{
		if (!base.Enabled)
		{
			Color[] desaturatedColors = DesaturateColors(thumbOuterColor, thumbInnerColor, thumbPenColor, barOuterColor, barInnerColor, barPenColor, elapsedOuterColor, elapsedInnerColor, tipColor);
			DrawColorSlider(e, desaturatedColors[0], desaturatedColors[1], desaturatedColors[2], desaturatedColors[3], desaturatedColors[4], desaturatedColors[5], desaturatedColors[6], desaturatedColors[7], desaturatedColors[8]);
		}
		else if (mouseEffects && mouseInRegion)
		{
			Color[] lightenedColors = LightenColors(thumbOuterColor, thumbInnerColor, thumbPenColor, barOuterColor, barInnerColor, barPenColor, elapsedOuterColor, elapsedInnerColor, tipColor);
			DrawColorSlider(e, lightenedColors[0], lightenedColors[1], lightenedColors[2], lightenedColors[3], lightenedColors[4], lightenedColors[5], lightenedColors[6], lightenedColors[7], lightenedColors[8]);
		}
		else
		{
			DrawColorSlider(e, thumbOuterColor, thumbInnerColor, thumbPenColor, barOuterColor, barInnerColor, barPenColor, elapsedOuterColor, elapsedInnerColor, tipColor);
		}
	}

	private void DrawColorSlider(PaintEventArgs e, Color thumbOuterColorPaint, Color thumbInnerColorPaint, Color thumbPenColorPaint, Color barOuterColorPaint, Color barInnerColorPaint, Color barPenColorPaint, Color elapsedOuterColorPaint, Color elapsedInnerColorPaint, Color tipColorPaint)
	{
		try
		{
			if (barOrientation == Orientation.Horizontal)
			{
				int TrackX = (trackerValue - barMinimum) * (base.ClientRectangle.Width - thumbSize) / (barMaximum - barMinimum);
				thumbRect = new Rectangle(TrackX, 1, thumbSize - 1, base.ClientRectangle.Height - 3);
			}
			else
			{
				int TrackY = (trackerValue - barMinimum) * (base.ClientRectangle.Height - thumbSize) / (barMaximum - barMinimum);
				thumbRect = new Rectangle(1, TrackY, base.ClientRectangle.Width - 3, thumbSize - 1);
			}
			if (_tipMin != -1 && _tipMax != -1)
			{
				if (barOrientation == Orientation.Horizontal)
				{
					int tipminX = (_tipMin - barMinimum) * base.ClientRectangle.Width / (barMaximum - barMinimum);
					int tipmaxX = (_tipMax - barMinimum) * base.ClientRectangle.Width / (barMaximum - barMinimum);
					int newtipminX = ((tipminX <= tipmaxX) ? tipminX : tipmaxX);
					int newtipmaxX = ((tipminX > tipmaxX) ? tipminX : tipmaxX);
					tipRect = new Rectangle(newtipminX, 1, newtipmaxX - newtipminX + 1, base.ClientRectangle.Height - 1);
				}
				tipRect.Inflate(-1, -tipRect.Height / 3);
				tipHalfRect = tipRect;
				tipHalfRect.Height /= 2;
			}
			barRect = base.ClientRectangle;
			thumbHalfRect = thumbRect;
			LinearGradientMode gradientOrientation;
			if (barOrientation == Orientation.Horizontal)
			{
				barRect.Inflate(-1, -barRect.Height / 3);
				barHalfRect = barRect;
				barHalfRect.Height /= 2;
				gradientOrientation = LinearGradientMode.Vertical;
				thumbHalfRect.Height /= 2;
				elapsedRect = barRect;
				elapsedRect.Width = thumbRect.Left + thumbSize / 2;
			}
			else
			{
				barRect.Inflate(-barRect.Width / 3, -1);
				barHalfRect = barRect;
				barHalfRect.Width /= 2;
				gradientOrientation = LinearGradientMode.Horizontal;
				thumbHalfRect.Width /= 2;
				elapsedRect = barRect;
				elapsedRect.Height = thumbRect.Top + thumbSize / 2;
			}
			GraphicsPath thumbPath;
			if (thumbCustomShape == null)
			{
				thumbPath = CreateRoundRectPath(thumbRect, thumbRoundRectSize);
			}
			else
			{
				thumbPath = thumbCustomShape;
				Matrix i = new Matrix();
				i.Translate((float)thumbRect.Left - thumbPath.GetBounds().Left, (float)thumbRect.Top - thumbPath.GetBounds().Top);
				thumbPath.Transform(i);
			}
			using (LinearGradientBrush lgbBar = new LinearGradientBrush(barHalfRect, barOuterColorPaint, barInnerColorPaint, gradientOrientation))
			{
				lgbBar.WrapMode = WrapMode.TileFlipXY;
				e.Graphics.FillRectangle(lgbBar, barRect);
				try
				{
					if (_tipMin != -1 && _tipMax != -1 && _tipMax >= 0 && _tipMin >= 0)
					{
						using LinearGradientBrush lgbTip = new LinearGradientBrush(tipHalfRect, tipColorPaint, tipColorPaint, gradientOrientation);
						lgbTip.WrapMode = WrapMode.TileFlipXY;
						e.Graphics.FillRectangle(lgbTip, tipRect);
					}
				}
				catch (Exception)
				{
				}
				using Pen barPen = new Pen(barPenColorPaint, 0.5f);
				e.Graphics.DrawRectangle(barPen, barRect);
			}
			Color newthumbOuterColorPaint = thumbOuterColorPaint;
			Color newthumbInnerColorPaint = thumbInnerColorPaint;
			if (base.Capture && drawSemitransparentThumb)
			{
				newthumbOuterColorPaint = Color.FromArgb(175, thumbOuterColorPaint);
				newthumbInnerColorPaint = Color.FromArgb(175, thumbInnerColorPaint);
			}
			using (LinearGradientBrush lgbThumb = new LinearGradientBrush(thumbHalfRect, newthumbOuterColorPaint, newthumbInnerColorPaint, gradientOrientation))
			{
				lgbThumb.WrapMode = WrapMode.TileFlipXY;
				e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
				e.Graphics.FillPath(lgbThumb, thumbPath);
				Color newThumbPenColor = thumbPenColorPaint;
				if (mouseEffects && (base.Capture || mouseInThumbRegion))
				{
					newThumbPenColor = ControlPaint.Dark(newThumbPenColor);
				}
				using Pen thumbPen = new Pen(newThumbPenColor);
				e.Graphics.DrawPath(thumbPen, thumbPath);
			}
			if (!(Focused & drawFocusRectangle))
			{
				return;
			}
			using Pen p = new Pen(Color.FromArgb(200, barPenColorPaint));
			p.DashStyle = DashStyle.Dot;
			Rectangle r = base.ClientRectangle;
			r.Width -= 2;
			r.Height--;
			r.X++;
			using GraphicsPath gpBorder = CreateRoundRectPath(r, borderRoundRectSize);
			e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
			e.Graphics.DrawPath(p, gpBorder);
		}
		catch (Exception)
		{
		}
		finally
		{
		}
	}

	protected override void OnEnabledChanged(EventArgs e)
	{
		base.OnEnabledChanged(e);
		Invalidate();
	}

	protected override void OnMouseEnter(EventArgs e)
	{
		base.OnMouseEnter(e);
		mouseInRegion = true;
		Invalidate();
	}

	protected override void OnMouseLeave(EventArgs e)
	{
		base.OnMouseLeave(e);
		mouseInRegion = false;
		mouseInThumbRegion = false;
		Invalidate();
	}

	protected override void OnMouseDown(MouseEventArgs e)
	{
		base.OnMouseDown(e);
		if (e.Button == MouseButtons.Left)
		{
			base.Capture = true;
			if (this.Scroll != null)
			{
				this.Scroll(this, new ScrollEventArgs(ScrollEventType.ThumbTrack, trackerValue));
			}
			if (this.ValueChanged != null)
			{
				this.ValueChanged(this, new EventArgs());
			}
			OnMouseMove(e);
		}
	}

	protected override void OnMouseMove(MouseEventArgs e)
	{
		base.OnMouseMove(e);
		mouseInThumbRegion = IsPointInRect(e.Location, thumbRect);
		if (base.Capture & (e.Button == MouseButtons.Left))
		{
			ScrollEventType set = ScrollEventType.ThumbPosition;
			Point pt = e.Location;
			int p = ((barOrientation == Orientation.Horizontal) ? pt.X : pt.Y);
			int margin = thumbSize >> 1;
			p -= margin;
			float coef = (float)(barMaximum - barMinimum) / (float)(((barOrientation == Orientation.Horizontal) ? base.ClientSize.Width : base.ClientSize.Height) - 2 * margin);
			trackerValue = (int)((float)p * coef + (float)barMinimum);
			if (trackerValue <= barMinimum)
			{
				trackerValue = barMinimum;
				set = ScrollEventType.First;
			}
			else if (trackerValue >= barMaximum)
			{
				trackerValue = barMaximum;
				set = ScrollEventType.Last;
			}
			if (this.Scroll != null)
			{
				this.Scroll(this, new ScrollEventArgs(set, trackerValue));
			}
			if (this.ValueChanged != null)
			{
				this.ValueChanged(this, new EventArgs());
			}
		}
		Invalidate();
	}

	protected override void OnMouseUp(MouseEventArgs e)
	{
		base.OnMouseUp(e);
		base.Capture = false;
		mouseInThumbRegion = IsPointInRect(e.Location, thumbRect);
		if (this.Scroll != null)
		{
			this.Scroll(this, new ScrollEventArgs(ScrollEventType.EndScroll, trackerValue));
		}
		if (this.ValueChanged != null)
		{
			this.ValueChanged(this, new EventArgs());
		}
		Invalidate();
	}

	protected override void OnMouseWheel(MouseEventArgs e)
	{
		base.OnMouseWheel(e);
		int v = e.Delta / 120 * (barMaximum - barMinimum) / mouseWheelBarPartitions;
		SetProperValue(Value + v);
	}

	protected override void OnGotFocus(EventArgs e)
	{
		base.OnGotFocus(e);
		Invalidate();
	}

	protected override void OnLostFocus(EventArgs e)
	{
		base.OnLostFocus(e);
		Invalidate();
	}

	protected override void OnKeyUp(KeyEventArgs e)
	{
		base.OnKeyUp(e);
		switch (e.KeyCode)
		{
		case Keys.Left:
		case Keys.Down:
			SetProperValue(Value - (int)smallChange);
			if (this.Scroll != null)
			{
				this.Scroll(this, new ScrollEventArgs(ScrollEventType.SmallDecrement, Value));
			}
			break;
		case Keys.Up:
		case Keys.Right:
			SetProperValue(Value + (int)smallChange);
			if (this.Scroll != null)
			{
				this.Scroll(this, new ScrollEventArgs(ScrollEventType.SmallIncrement, Value));
			}
			break;
		case Keys.Home:
			Value = barMinimum;
			break;
		case Keys.End:
			Value = barMaximum;
			break;
		case Keys.Next:
			SetProperValue(Value - (int)largeChange);
			if (this.Scroll != null)
			{
				this.Scroll(this, new ScrollEventArgs(ScrollEventType.LargeDecrement, Value));
			}
			break;
		case Keys.Prior:
			SetProperValue(Value + (int)largeChange);
			if (this.Scroll != null)
			{
				this.Scroll(this, new ScrollEventArgs(ScrollEventType.LargeIncrement, Value));
			}
			break;
		}
		if (this.Scroll != null && Value == barMinimum)
		{
			this.Scroll(this, new ScrollEventArgs(ScrollEventType.First, Value));
		}
		if (this.Scroll != null && Value == barMaximum)
		{
			this.Scroll(this, new ScrollEventArgs(ScrollEventType.Last, Value));
		}
		Point pt = PointToClient(Cursor.Position);
		OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, pt.X, pt.Y, 0));
	}

	protected override bool ProcessDialogKey(Keys keyData)
	{
		if ((keyData == Keys.Tab) | (Control.ModifierKeys == Keys.Shift))
		{
			return base.ProcessDialogKey(keyData);
		}
		OnKeyDown(new KeyEventArgs(keyData));
		return true;
	}

	public static GraphicsPath CreateRoundRectPath(Rectangle rect, Size size)
	{
		GraphicsPath gp = new GraphicsPath();
		gp.AddLine(rect.Left + size.Width / 2, rect.Top, rect.Right - size.Width / 2, rect.Top);
		gp.AddArc(rect.Right - size.Width, rect.Top, size.Width, size.Height, 270f, 90f);
		gp.AddLine(rect.Right, rect.Top + size.Height / 2, rect.Right, rect.Bottom - size.Width / 2);
		gp.AddArc(rect.Right - size.Width, rect.Bottom - size.Height, size.Width, size.Height, 0f, 90f);
		gp.AddLine(rect.Right - size.Width / 2, rect.Bottom, rect.Left + size.Width / 2, rect.Bottom);
		gp.AddArc(rect.Left, rect.Bottom - size.Height, size.Width, size.Height, 90f, 90f);
		gp.AddLine(rect.Left, rect.Bottom - size.Height / 2, rect.Left, rect.Top + size.Height / 2);
		gp.AddArc(rect.Left, rect.Top, size.Width, size.Height, 180f, 90f);
		return gp;
	}

	public static Color[] DesaturateColors(params Color[] colorsToDesaturate)
	{
		Color[] colorsToReturn = new Color[colorsToDesaturate.Length];
		for (int i = 0; i < colorsToDesaturate.Length; i++)
		{
			int gray = (int)((double)(int)colorsToDesaturate[i].R * 0.3 + (double)(int)colorsToDesaturate[i].G * 0.6 + (double)(int)colorsToDesaturate[i].B * 0.1);
			colorsToReturn[i] = Color.FromArgb(-65793 * (255 - gray) - 1);
		}
		return colorsToReturn;
	}

	public static Color[] LightenColors(params Color[] colorsToLighten)
	{
		Color[] colorsToReturn = new Color[colorsToLighten.Length];
		for (int i = 0; i < colorsToLighten.Length; i++)
		{
			colorsToReturn[i] = ControlPaint.Light(colorsToLighten[i]);
		}
		return colorsToReturn;
	}

	private void SetProperValue(int val)
	{
		if (val < barMinimum)
		{
			Value = barMinimum;
		}
		else if (val > barMaximum)
		{
			Value = barMaximum;
		}
		else
		{
			Value = val;
		}
	}

	private static bool IsPointInRect(Point pt, Rectangle rect)
	{
		if ((pt.X > rect.Left) & (pt.X < rect.Right) & (pt.Y > rect.Top) & (pt.Y < rect.Bottom))
		{
			return true;
		}
		return false;
	}

	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	private void InitializeComponent()
	{
		base.SuspendLayout();
		base.Size = new System.Drawing.Size(200, 30);
		base.ResumeLayout(false);
	}
}
